package com.example.smartall.ui;

import androidx.cardview.widget.CardView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.smartall.R;
import com.example.smartall.api.Api;
import com.example.smartall.api.ApiConfig;
import com.example.smartall.api.NetCallBack;
import com.example.smartall.entity.HospitalCategoryBean;
import com.example.smartall.fragment.Hospital.CommonFragment;
import com.example.smartall.ui.base.BaseActivity;
import com.example.smartall.utils.Constant;
import com.example.smartall.utils.SPUtils;

import java.util.HashMap;

/**
 * 挂号信息页面 22/1/29 门诊模块到此结束
 */

 /**
  * @Author:         abbas
  * @CreateDate:     2022/1/29
  * @Description:    终于弄好这个快捷注释了
  */
           //HospitalRegisterDetails
public class HRDetailsActivity extends BaseActivity {
    private ImageView imBack;
    private TextView tvTitle;
    private CardView cvDetails;
    private TextView tvKs;
    private TextView tvLx;
    private TextView tvSj;
    private Button btRegistered;

    private CommonFragment.DataBean timeBean;
    private HospitalCategoryBean.RowsBean dataBean;
    private String patientName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hrdetails);

        timeBean = (CommonFragment.DataBean) getIntent().getSerializableExtra("time");
        dataBean = (HospitalCategoryBean.RowsBean) getIntent().getSerializableExtra("data");
        patientName = getIntent().getStringExtra("name");

        init();
        initEvent();
        register();
    }

    @Override
    public void init() {
        imBack = (ImageView) findViewById(R.id.im_back);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        cvDetails = (CardView) findViewById(R.id.cv_details);
        tvKs = (TextView) findViewById(R.id.tv_ks);
        tvLx = (TextView) findViewById(R.id.tv_lx);
        tvSj = (TextView) findViewById(R.id.tv_sj);
        btRegistered = (Button) findViewById(R.id.bt_registered);

        tvTitle.setText("挂号信息");
        tvKs.setText("预约科室："+dataBean.getCategoryName());
        tvLx.setText("门诊类型：普通号");
        tvSj.setText(timeBean.getDate() + timeBean.getWhen() + timeBean.getTime());
    }

    @Override
    public void initEvent() {
        imBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getThis().finish();
            }
        });
        btRegistered.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //TODO 点击预约成功返回首页
                HRDetailsActivity.super.destroyLater();
            }
        });
    }

    private void register(){
        HashMap<String,Object> params = new HashMap<>();
        params.put("categoryId",dataBean.getId());
        params.put("money",dataBean.getMoney());
        params.put("patientName",patientName);
        params.put("reserveTime",timeBean.getDate()+" "+timeBean.getTime());
        params.put("type", dataBean.getType());
        Api.config(ApiConfig.HOSPITAL_REGISTER,params).postRequest(new NetCallBack() {
            @Override
            public void onSuccess(String res) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        btRegistered.setVisibility(View.VISIBLE);
                    }
                });
            }

            @Override
            public void onFailure(Exception e) {

            }
        },SPUtils.config(HRDetailsActivity.this, Constant.SP_USER_FILE_NAME).getString(Constant.TOKEN));
    }
}